﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using KvoMvc.BusinessEntity;
using KvoMvc.BusinessContract;


namespace KvoMvc.ServiceProxy
{
    public interface ISchoolManagerProxyChannel : ISchoolManager, IClientChannel
    { } 

    public class SchoolManagerProxy
    {
        #region Person

        public static Person GetPersonById(int id)
        {
            ISchoolManagerProxyChannel manager = ProxyHelper.CreateRemoteObject<ISchoolManagerProxyChannel>("KvoMvc.BusinessContract.ISchoolManager");
            using (OperationContextScope scope = new OperationContextScope(manager))
            {

                Person result = manager.GetPersonById(id);
                ((IClientChannel)manager).Close();
                return result;
            }
        }

        public static List<Person> GetPersonList()
        {
            ISchoolManagerProxyChannel manager = ProxyHelper.CreateRemoteObject<ISchoolManagerProxyChannel>("KvoMvc.BusinessContract.ISchoolManager");
            using (OperationContextScope scope = new OperationContextScope(manager))
            {

                List<Person> results = manager.GetPersonList();
                ((IClientChannel)manager).Close();
                return results;
            }
        }

        public static int CreatePerson(Person person)
        {
            ISchoolManagerProxyChannel manager = ProxyHelper.CreateRemoteObject<ISchoolManagerProxyChannel>("KvoMvc.BusinessContract.ISchoolManager");
            using (OperationContextScope scope = new OperationContextScope(manager))
            {
                int result = manager.CreatePerson(person);
                ((IClientChannel)manager).Close();
                return result;
            }
        }

        public static int UpdatePerson(Person person)
        {
            ISchoolManagerProxyChannel manager = ProxyHelper.CreateRemoteObject<ISchoolManagerProxyChannel>("KvoMvc.BusinessContract.ISchoolManager");
            using (OperationContextScope scope = new OperationContextScope(manager))
            {

                int result = manager.UpdatePerson(person);
                ((IClientChannel)manager).Close();
                return result;
            }
        }

        #endregion

        #region Department

        public static List<Department> GetDepartmentList()
        {
            ISchoolManagerProxyChannel manager = ProxyHelper.CreateRemoteObject<ISchoolManagerProxyChannel>("KvoMvc.BusinessContract.ISchoolManager");
            using (OperationContextScope scope = new OperationContextScope(manager))
            {

                List<Department> results = manager.GetDepartmentList();
                ((IClientChannel)manager).Close();
                return results;
            }
        }
        
        #endregion
    }
}
